import { fileURLToPath, URL } from 'node:url'

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'


// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), '');
  const targetUrl = env.VITE_APP_BASE_API;
  
  return {
    plugins: [
      vue(),
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      // host: '0.0.0.0', //ip地址
      // port: 2048,
      open: true, //启动后是否自动打开浏览器
      proxy: {
        '/api': {
          target: "http://localhost:2048/", //跨域地址
          changeOrigin: true, //支持跨域
          rewrite: (path) => path.replace(/^\/api/, "")//重写路径,替换/api
        },
        '/ws': {
          target: 'ws://localhost:2048/',
          ws: true, // 启用 WebSocket 支持
        }
      }
    },
  }
})
